﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Library
{
    public partial class ChiTietDDH
    {
        internal static List<ChiTietDDH> GetListByMa(int MaDDH)
        {
            List<ChiTietDDH> result = new List<ChiTietDDH>();

            QLDCTTEntities da = new QLDCTTEntities();

            try
            {
                result = (from dh in da.ChiTietDDH
                          where dh.MaDDH == MaDDH
                          select dh).ToList();
            }

            catch (Exception ex)
            {
                throw ex;
            }

            return result;
        }

        internal static void Delete(ChiTietDDH bizdh)
        {
            try
            {
                QLDCTTEntities entities = new QLDCTTEntities();
                ChiTietDDH dh = entities.ChiTietDDH.Single(p => p.ID == bizdh.ID);

                entities.ChiTietDDH.Remove(dh);

                entities.SaveChanges();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        internal static void Add(ChiTietDDH bizddh)
        {
            try
            {
                ChiTietDDH ddh = new ChiTietDDH();
                ddh.MaDDH = bizddh.MaDDH;
                ddh.ID_SP = bizddh.ID_SP;
                ddh.SoLuong = bizddh.SoLuong;

                QLDCTTEntities entities = new QLDCTTEntities();
                entities.ChiTietDDH.Add(ddh);

                entities.SaveChanges();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
    }
}
